package com.example.ui.share.adapter;

import java.util.ArrayList;

import com.example.huashangapp.R;
import com.example.ui.learn.util.CurriculumCenter;

import com.example.ui.leftmenu.Circle;
import com.example.util.BitmapLoad;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AroundCircleAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private ArrayList<Circle> list;
	private Context mContext;
	public AroundCircleAdapter(Context mContext,ArrayList<Circle> list){
		this.mContext = mContext;
        this.list=list;
		inflater = LayoutInflater.from(mContext);
	}
	public ArrayList<Circle> getCcInfos() {
		return list;
	}

	public void setCcInfos(ArrayList<Circle> list) {
		this.list = list;
		if (list == null) {
			this.list = new ArrayList<Circle>();
		}
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder = null;
		Circle c=list.get(position);
		if(convertView == null){
			convertView = inflater.inflate(R.layout.around_cirle_listview_item, null);
			holder = new Holder();
        	holder.img = (ImageView)convertView.findViewById(R.id.around_cicle_item_img);
			holder.textName = (TextView) convertView.findViewById(R.id.around_cicle_item_name);
			holder.textPeopleNum = (TextView) convertView.findViewById(R.id.around_cicle_item_num_people);
			holder.textCommentNum = (TextView) convertView.findViewById(R.id.around_cicle_item_num_comment);
			holder.textdistance = (TextView) convertView.findViewById(R.id.around_cicle_item_distance);
			holder.textContent = (TextView) convertView.findViewById(R.id.around_cicle_item_content);
        	convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
		String imgStr = c.getThumb().toString();
		if(!"".equals(imgStr)||null!=imgStr){
			holder.img.setImageBitmap(BitmapLoad.loadBitmap(mContext, imgStr));
//			Bitmap bit = BitmapLoad.loadBitmap(mContext, imgStr);
//			holder.img.setBackgroundDrawable(new BitmapDrawable(bit));
		}else{
			holder.img.setBackgroundResource(R.drawable.head_bg);
		}
		holder.textName.setText(c.getTitle());
		holder.textPeopleNum.setText(c.getJoinNum());
		holder.textCommentNum.setText(c.getShareNum());
		holder.textdistance.setText(c.getDistance());
		holder.textContent.setText(c.getIntro());
		return convertView;
	}
	
	class Holder{
    	ImageView img;
    	TextView textName;
    	TextView textPeopleNum;
    	TextView textCommentNum;
    	TextView textdistance;
    	TextView textContent;
    }
	

}
